<?php
	class CommonAction extends Action{
		public function __construct(){
			$autoload=$_COOKIE['isautoload'];
			//检测是否已经登录
			if(!$_SESSION[C('USER_AUTH_KEY')]['isload']){//如果没有登录
				//检测是否需要自动登录
				if($autoload=='autoload'){
					$user=$_COOKIE['UserName'];
					$pwd=$_COOKIE['Password'];
					$res=M('users')->query('SELECT UserId,UserName,OrgLocation,OrgName,PhoneNumber,Email,UserType,Avatar,TrueName,IsApproved,IsJury FROM `users` WHERE ( UserName="'.$user.'" AND Password="'.$pwd.'" ) LIMIT 1');
					if($res){
						$_SESSION[C('USER_AUTH_KEY')]=$res[0];
						$_SESSION[C('USER_AUTH_KEY')]['isload']=1;
					}
				}
			}
			//如果登录了，将进行新邮件的查询。
			if($_SESSION[C('USER_AUTH_KEY')]['isload']){
				$_SESSION[C('USER_AUTH_KEY')]['newmailnum']=$this->newmailnum();
			}
		}
		
		//新邮件数
		public function newmailnum(){
			$mail = M()->query('select count(Id) num from mail where Receiverid='.$_SESSION[C('USER_AUTH_KEY')]['UserId'].' and IsRead=0 and IsDeleted=0');
			return $mail[0]['num'];
		}
		
		
	}
?>